package com.androidhuman.example.ActionViewNavigation;

import android.app.ActionBar;
import android.app.ActionBar.OnNavigationListener;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.SearchView;
import android.widget.SearchView.OnQueryTextListener;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class ActionViewNavigationActivity extends Activity implements OnNavigationListener, OnQueryTextListener {
    
	private TextView queryText;
	private String[] lists = new String[] {"Android", "Chrome", "Google"};
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        queryText = (TextView)findViewById(R.id.queryText);
        
        ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        
        SpinnerAdapter adapter = 
        		new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,lists);
        
        actionBar.setListNavigationCallbacks(adapter, this);
        
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu){
    	getMenuInflater().inflate(R.menu.menu, menu);
    	SearchView sv = (SearchView)menu.findItem(R.id.menu_search).getActionView();
    	sv.setOnQueryTextListener(this);
		return true;
    	
    } 

	@Override
	public boolean onNavigationItemSelected(int itemPosition, long itemId) {
		// TODO Auto-generated method stub
		Toast.makeText(this, "Selected position : " + itemPosition, Toast.LENGTH_SHORT).show();
		return false;
	}

	@Override
	public boolean onQueryTextChange(String newText) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean onQueryTextSubmit(String query) {
		// TODO Auto-generated method stub
		queryText.setText(query);
		return false;
	}
}